<!DOCTYPE html>
<html lang="en">
casxasxa
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
    </div>
    <script>
        // 虚拟dom 就是一个js对象，用于描述dom节点得js对象，将这个js对象转换为真实得dom
        var app1 = {
            type: "div",
            props: {
                class: "box",
                children: [{
                        type: "span",
                        props: {
                            children: ["hellow"]
                        }
                    },
                    {
                        type: "span",
                        props: {
                            children: ["hellow1"]
                        }
                    },
                ]
            }
        }


        function render(jsx, root) { // 将虚拟dom对象渲染成真实得dom节点
            // 下面一行为创建元素的方法
            let createElement = (jsx, parent) => {
                let cur = null // 用于承接创建出来的dom元素
                let {
                    type,
                    props
                } = jsx
                if (typeof (jsx) == "string") {
                    cur = document.createTextNode(jsx)
                    parent.append(cur)
                } else {
                    cur = document.createElement(type)
                    parent.append(cur)
                    console.log(Object.keys(props))
                    Object.keys(props).forEach((item, index) => {
                        if (item == "class") {
                            cur.setAttribute('class', props[item])
                        } else if (item == "children") {
                            if (Array.isArray(props[item])) {
                                props[item].map((val => {
                                    createElement(val, cur)
                                }))
                            }
                        }
                    })
                }

            }
            createElement(jsx, root)
        }
        // id 名不用获取
        render(app1, app)
    </script>
</body>

</html>